package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC396 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxRotateFunction(int[] arr) {
            int base = 0, res = 0, sum = 0, curRotate = 0, n = arr.length;
            for (int i = 0; i < arr.length; i++) {
                int num = arr[i];
                sum += num;
                base += (i * num);
            }

            res = base;
            curRotate = base;
            for (int i = 1; i < arr.length; i++) {
                curRotate = curRotate + sum - n * arr[n - i];
                res = Math.max(res, curRotate);
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[4, 3, 2, 6]");
        System.out.println(solution.maxRotateFunction(arr));
    }

    public static void main(String[] args) throws Exception {
        LC396 an = new LC396();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
